package com.cloud.controller;


import com.cloud.pojo.User;
import com.cloud.service.UserService;
import com.cloud.vo.CloudResult;
import com.cloud.vo.UpdatePsdvo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author haoyeee123
 * @since 2022-01-15
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    /*
     * 用户登录
     * */
    @PostMapping("/validate")
    public CloudResult selectUser(@RequestBody User user){
        User userDB = userService.selectUser(user);
        if (userDB==null){
            return CloudResult.fail();
        }
        return CloudResult.success(userDB);
    }
    /*
    * 用户注册
    * */
    @PostMapping("/add")
    public CloudResult addUser(@RequestBody User user){
        int flag = userService.addUser(user);
        if (flag==0){
            return CloudResult.fail();
        }
        return CloudResult.success();
    }
    /*
    * 用户更新密码
    * */
    @PostMapping("/update")
    public CloudResult updateUser(@RequestBody UpdatePsdvo params){
        int flag = userService.updateUser(params);
        if (flag == 0){
            return CloudResult.fail();
        }
        return CloudResult.success();
    }
    /*
    * 用户开通会员
    * */
    @PostMapping("addVIP")
    public CloudResult addVIP(@RequestBody User user){
        int flag = userService.addVIP(user);
        if (flag == 0){
            return CloudResult.fail();
        }
        if (flag == 201){
            return CloudResult.fail().setFlag(201);
        }
        return CloudResult.success();
    }


}

